﻿using Autodesk.Revit.DB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace demo.Extensions
{
    public static class RevitExtension
    {


        /// <summary>
        /// 英尺转毫米
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public static double ToMM(this double b)
        {
            return UnitUtils.Convert(b, DisplayUnitType.DUT_DECIMAL_FEET, DisplayUnitType.DUT_MILLIMETERS);
        }
        /// <summary>
        /// 毫米转英尺
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public static double ToFeet(this double b)
        {
            return UnitUtils.Convert(b, DisplayUnitType.DUT_MILLIMETERS, DisplayUnitType.DUT_DECIMAL_FEET);
        }


        public static double CmToFeet(this double b)
        {
            //var d = b / 10;
            //return UnitUtils.Convert(d, DisplayUnitType.DUT_MILLIMETERS, DisplayUnitType.DUT_DECIMAL_FEET);
           return UnitUtils.ConvertToInternalUnits(b, DisplayUnitType.DUT_MILLIMETERS);

        }


        /// <summary>
        /// 平方英尺转平方米
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public static double ToSquareMeters(this double b)
        {
            return UnitUtils.Convert(b, DisplayUnitType.DUT_SQUARE_FEET, DisplayUnitType.DUT_SQUARE_METERS);
        }
        /// <summary>
        /// 平方米转平方英尺
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public static double ToSquareFeet(this double b)
        {
            return UnitUtils.Convert(b, DisplayUnitType.DUT_SQUARE_METERS, DisplayUnitType.DUT_SQUARE_FEET);
        }

        public static double MM(this double value)
        {
            // return value;
            return UnitUtils.ConvertToInternalUnits(value, DisplayUnitType.DUT_MILLIMETERS);
        }

        public static double Cos(this double value)
        { 
            return Math.Cos(value);
        }
        public static double Sin(this double value)
        {
            return Math.Sin(value);
        }


        /// <summary>
        /// 角度转换弧度
        /// </summary>
        /// <param name="degree">角度值</param>
        /// <returns>弧度</returns>
        public static double DegreeToAngle2(this double degree)
        {
            return degree.GetAngle() * Math.PI / 180;
        }

        /// <summary>
        /// 角度转换弧度
        /// </summary>
        /// <param name="degree">角度值</param>
        /// <returns>弧度</returns>
        public static double DegreeToAngle(this double degree)
        {
            return degree* Math.PI / 180;
        }


        public static double GetAngle(this double value)
        {
            if (value < 0)
            {
                var d1 = value + 360;
                if (d1 > 180)
                {
                    return 360 - d1;
                }
                return d1;
            }
            else if (value >= 0 && value <= 180)
            {
                return value;
            }
            else if (value > 180)
            {
                return 360 - value;
            }
            else
            {
                return 0;
            }
        
        }

        /// <summary>
        /// 弧度转换角度
        /// </summary>
        /// <param name="angle">弧度值</param>
        /// <returns>角度</returns>
        public static double AngleToDegree(this double angle)
        {
            return angle * 180 / Math.PI;
        }


    }
}
